<template>
  <div class="mod-bug">
    <el-form :inline="true" :model="searchForm" @keyup.enter.native="initPage()">
      <el-form-item>
        <el-input v-model="searchForm.name" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="initPage()">查询</el-button>
        <el-button v-if="isAuth('zt:bug:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('zt:bug:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="project"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="product"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="injection"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="identify"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="branch"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="module"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="execution"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="plan"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="story"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="storyversion"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="task"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="totask"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="tostory"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="title"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="keywords"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="severity"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="pri"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="type"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="os"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="browser"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="hardware"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="found"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="steps"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="substatus"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="color"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="confirmed"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="activatedcount"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="activateddate"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="feedbackby"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="notifyemail"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="mailto"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="openedby"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="openeddate"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="openedbuild"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="assignedto"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="assigneddate"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="deadline"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="resolvedby"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="resolution"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="resolvedbuild"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="resolveddate"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="closedby"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="closeddate"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="duplicatebug"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="linkbug"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="case"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="caseversion"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="feedback"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="result"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="repo"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="mr"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="entry"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="lines"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="v1"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="v2"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="repotype"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="issuekey"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="testtask"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="lasteditedby"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="lastediteddate"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="deleted"
        header-align="center"
        :show-overflow-tooltip="true"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('zt:bug:info')" type="text" size="small" @click="showDetails(scope.row.id)">查看</el-button>
          <el-button v-if="isAuth('zt:bug:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button v-if="isAuth('zt:bug:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './bug-add-or-update'

  export default {
    data () {
      return {
        searchForm: {
          name: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 页面初始化
      initPage () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.$http({
          url: '/zt/bug/list',
          method: 'get',
          params: {
            'page': this.pageIndex,
            'limit': this.pageSize,
            'name': this.searchForm.name
          }
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.records
            this.totalPage = data.page.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 查看详情
      showDetails (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, true)
        })
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        let ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[删除]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: '/zt/bug/delete',
            method: 'post',
            data: ids
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.getDataList()
            }
          })
        }).catch(() => {
        })
      }
    }
  }
</script>
